package com.study.entity;

import com.study.frame.TankWarFrame;
import com.study.manager.ResourceManager;
import com.study.utils.ApplicationComponent;

import java.awt.*;

/**
 * 坦克爆炸
 * @Author ZhuHJay
 * @Date 2021/9/15 16:08
 */
public class Explode {

    /** 坐标 **/
    private int x, y;

    /** 大小 **/
    public static final int EXPLODE_WIDTH = ResourceManager.explodes.get(0).getWidth();
    public static final int EXPLODE_HEIGHT = ResourceManager.explodes.get(0).getHeight();

    /** 当前展示到的图片索引 **/
    private int index;

    /** 是否展示 **/
    private boolean show = true;

    /** 构造方法 **/
    public Explode(int x, int y){
        this.x = x;
        this.y = y;
        index = 0;
    }

    /** 绘制方法 **/
    public void paint(Graphics graphics){
        if( !isShow() ){
            ApplicationComponent.getBean(TankWarFrame.class).removeExplode(this);
            return;
        }
        Color color = graphics.getColor();
        // 绘制
        graphics.drawImage(ResourceManager.explodes.get(index++), x, y, null);
        // 如果超出图片展示范围, 那么就停止
        if( index >= ResourceManager.explodes.size() ){
            show = false;
        }
        graphics.setColor(color);
    }

    public boolean isShow() {
        return show;
    }

}
